﻿// Copyright 2008 Benjamin Jenks 
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may 
// not use this file except in compliance with the License. You may obtain 
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License. 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

using iTunesLib;

namespace iTunesAlbumArtFetcher.Core
{
    public class iTunes
    {
        iTunesApp itunes= new iTunesApp();

        public class Track {
            private IITTrack track;

            public Track(IITTrack track) {
                this.track= track;
            }

            public string Artist {
                get { return this.track.Artist; }
            }
            public string Album {
                get { return this.track.Album; }
            }
            public string Name {
                get { return this.track.Name; }
            }
            public string Artwork {
                set { this.track.AddArtworkFromFile( value ); }
            }
            public override string ToString() {
                return this.track + " by " + this.Artist + " from " + this.Album;
            }
        }

        public IEnumerable<Track> TracksWithoutArtwork() {
            // find all the tracks without associated artwork
            foreach (IITTrack track in itunes.LibrarySource.Playlists[ 1 ].Tracks) {
                if (track.Artwork.Count == 0) {
                    yield return new Track( track );
                }
            }
        }
    }
}